<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- 引入layui 样式-->
    <link rel="stylesheet" href="../../static/layer/css/layui.css"/>
    <link rel="stylesheet" href="../../static/css/font-awesome.min.css">
    <script type="text/javascript" src="../../static/layer/layui.js"></script>
</head>
<body>
<div class="layui-tab layui-tab-brief" lay-filter="expense_management">
    <div class="layui-tab-content">
        <!--审批中的业务-->
        <div class="layui-tab-item layui-show">
            <div class="operateTable">
                <div class="layui-inline">
                    <input class="layui-input" name="LOAN_PRICE" id="LOAN_PRICE" placeholder="借款金额">
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="COMPANY_NAME" id="COMPANY_NAME" placeholder="借款方名称">
                </div>
                <!--<div class="layui-inline">
                    <input class="layui-input" name="BY_NAME" id="BY_NAME" placeholder="别名">
                </div>-->
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <table id="contractZancun" lay-filter="zancunf"></table>
                <!-- <script type="text/html" id="zancunbar">-->
                <div style="display: none;" id="zancunbar">
                    <a class="layui-btn  layui-btn-mini AUTH-MENU_YWQX_CK" lay-event="detail">查看</a>
                    <a class="layui-btn  layui-btn-mini layui-btn-normal AUTH-MENU_YWQX_XZ" lay-event="update">修改</a>
                    <a class="layui-btn  layui-btn-mini layui-btn-primary AUTH-MENU_YWQX_ZF" lay-event="zhongzhi">作废</a>
                    <!--<a class="layui-btn  layui-btn-mini layui-btn-danger" lay-event="del">删除</a>-->
                </div>
                <!-- </script> -->
            </div>
        </div>
    </div>
</div>
</div>
<script type="text/javascript" src="../../static/js/common/queryUtils.js"></script>
<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../static/js/common/authUtils.js"></script>
<script>
    // 加载元素控件
    var table;
    layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'table'], function () {
        $ = layui.jquery, element = layui.element, layer = layui.layer, form = layui.form, table = layui.table, laydate = layui.laydate;

        //初始化时间
        laydate.render({
            elem: '#START_DATE'
            , format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#END_DATE'
            , format: 'yyyy-MM-dd'
        });
        data={};
        //加载 新建的业务 合同
        table.render({
            elem: '#contractZancun'
            , url: '/LoanController/contractZancun'
            , where: data
            , cols: [[
                {field: 'ROWNUM', event: 'setSign', title: '序号', width: 60}
                // ,{field: 'TRNANTRY', event: 'setSign', title: '借款方类型', width: 120}
                ,{field: 'COMPANY_NAME', event: 'setSign', title: '借款方名称', width: 220}
                ,{field: 'LOAN_PRICE', event: 'setSign', title: '借款金额(元)', align:'right', width: 200,templet: '#tplMoney'}
                ,{field: 'BORROW_PERIOD', event: 'setSign',title: '借款期限(天)', width: 120}
                ,{field: 'CHECK_STATE', event: 'setSign',title: '状态', width: 120}
                ,{field: 'NAME', event: 'setSign', title: '创建人', width: 120}
                ,{field: 'CREATE_DATE', event: 'setSign', title: '创建时间', width: 180}
                ,{fixed: 'right', width: 250, align: 'center', title: '操作', toolbar: '#zancunbar'}

            ]]
            , id: 'CON_ID'
            , page: true
            , height: '470'
            , limit: '10'
        });

        //查询 待审批的业务
        $('.operateTable .layui-btn').on('click', function () {
            var data = {};
            data.COMPANY_NAME = $("#COMPANY_NAME").val();
            data.BYNAME = $("#BY_NAME").val();
            data.LOAN_PRICE = $("#LOAN_PRICE").val();
            table.reload('CON_ID', {
                where: data
            });
        });
        //暂存中的合同  操作
        table.on('tool(zancunf)', function (obj) {
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                parent.layer.open({
                    zIndex: 1000,
                    type: 2,    //弹出类型
                    title: '查看业务',   //标题
                    closeBtn: 1,    //显示关闭按钮
                    shade: [0.3],   //遮罩透明度
                    area: ['80%', '90%'],  //打开窗口的宽高
                    time: 0,    //几秒后自动关闭，默认0时不关闭
                    anim: 1,    //动画效果
                    resize: false,  //设置成不允许拉伸
                    content: '../../../webhtml/loan/bussiness_info.html?CONTRACT_ID=' + data.ID + ''+ '&IS_TITLE=show'  //iframe的url
                });
            } else if (layEvent === 'update') {
                parent.layer.open({
                    type: 2,    //弹出类型
                    title: '继续编辑',   //标题
                    closeBtn: 1,    //显示关闭按钮
                    shade: [0.3],   //遮罩透明度
                    area: ['1000px', '90%'],  //打开窗口的宽高
                    time: 0,    //几秒后自动关闭，默认0时不关闭
                    anim: 1,    //动画效果
                    resize: false,  //设置成不允许拉伸
                    content: '../../../webhtml/loan/loan_update.html?LOAN_ID=' + data.ID + "&TYPE=edit"+ '&IS_TITLE=edit',  //iframe的url,
                    end: function () {
                        table.reload("CON_ID",{});
                    }
                });
                $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
            }
            else if (layEvent === 'zhongzhi') {
                layer.msg('确定作废合同？', {
                    time: 20000, //20s后自动关闭
                    btn: ['确定', '取消',]
                    ,yes(index){
                        layer.close(index); // 关闭当前提示框
                        $.ajax({
                            url: "/LoanController/loanzuofei",
                            data: data,
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    var i = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(i);  // 关闭修改房间页面
                                    parent.layer.msg("作废成功", {offset: '150px'});   // 父页面弹出修改成功
                                    table.reload("CON_ID");
                                } else if (res.errcode === "1") {
                                    layer.msg(res.errmsg, function () {
                                    });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });

                    }
                });

            }
            else if (layEvent === 'del') {
                layer.msg('确定删除合同？', {
                    time: 20000, //20s后自动关闭
                    btn: ['确定', '取消',]
                    ,yes: function(index){
                        layer.close(index); // 关闭当前提示框
                        $.ajax({
                            url: "/contract/delete",
                            data: data,
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    var i = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(i);  // 关闭修改房间页面
                                    parent.layer.msg("删除成功", {offset: '150px'});   // 父页面弹出修改成功
                                    table.reload("CON_ID");
                                } else if (res.errcode === "1") {
                                    layer.msg(res.errmsg, function () {
                                    });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });

                    }
                });

            }
        });

    });

    //刷新暂存中合同
    function reloadBussiness() {
        table.reload("CON_ID",{});
    }
</script>
<script>
    function fixed(str) {
        if (!str) str = '0.00';
        let ret = Math.round(parseFloat(str) * 100) / 100;
        let decimal = ret.toString().split('.');
        if (decimal.length === 1) {
            return ret.toString() + '.00'
        }
        ;
        if (decimal.length > 1) {
            if (decimal[1].length < 2) {
                return ret.toString() + '0'
            }
            return ret
        }
        ;
        return ret;
    }
</script>
<script type="text/html" id="tplMoney">{{QueryUtils.fixedThousand((d.LOAN_PRICE),2)}}</script>
<!--到期合同 提示-->
<script type="text/html" id="contract_expires">
    {{#  if(d.EXPIRED==='1'){ }}
    {{# layer.tips('注意：到期合同', '#dd', {
    tips: [2, '#ff2134']
    }); }}
    <span style="color: #FF5722;">{{d.con_end_date}}</span>
    {{#  } else if(d.EXPIRED === "0"){ }}
    <span style="color: #79b819;">{{d.con_end_date}}</span>
    {{#  } else { }}
    异常
    {{#  }}}
</script>
</body>
</html>
